//spc module init js.

require(['jquery', 'business/searchbar/searchbarBiz', 'business/analysis/report/reportBiz', 'stringUtils', 'dateUtils'], function ($, searchbar, report, stringUtils, dateUtils) {
    var data = {
        searchFields: {}
    };

    pageSetUp();
    searchbar.init();

    //bind the searchEvent for get test items.
    report.init();
    searchbar.bindSearchEvent(report.searchEventListener);

    $('.collapseBtn').on('click', function (e, i) {
        var theOthers = $(this).parent().nextAll("div, ul");
        var img = $(this).find('span > i');
        theOthers.toggle();

        if (theOthers.is(":hidden")) {
            img.removeClass('fa-angle-down');
            img.addClass('fa-angle-left');
        } else {
            img.removeClass('fa-angle-left');
            img.addClass('fa-angle-down');
        }
    });

    searchbar.onCompleted(function () {
        data.searchFields = searchbar.getSearchFields();
        if (stringUtils.isBlank(data.searchFields.search_startTime) && stringUtils.isBlank(data.searchFields.search_stopTime)) {
            var obj = {
                "startTime": dateUtils.getYesterdayDateTime,
                "endTime": dateUtils.getCurrentDateTime
            };
            searchbar.setFieldsValue(obj);
        }
        searchbar.doSearch();
    });

});